<template>
  <div>
    <f-table ref='table' rowKey='paymentId' :columns='columns' :scroll='{x:true}' handler='paidInvoicePaymentPageListHandler' :multiple='false' :params='queryParam' :api='api.payment'>
    <span slot="invoiceType" slot-scope="text, record, index">
            <a-tag color="#108ee9" v-if="text==1">普票</a-tag>
            <a-tag color="#f50" v-if="text==2">专票</a-tag>
       </span>
     <span slot='action' slot-scope='text, record'>
          <template>
            <a @click='startProcess(record)' v-if='record.fkPaymentState==0&&record.fankuanId'>提交</a>
            <a @click='completeTask(record)' v-if="record.taskDefinitionKey&&record.taskDefinitionKey=='__initiator__'">提交</a>
            <a @click="$refs.refundDrewer.showDrawer(record,'form1')" v-if="record.fankuanId==''">申请返款</a>
              <a-divider type='vertical' />
          </template>
           <a-dropdown>
            <a class='ant-dropdown-link'>更多 <a-icon type='down' /></a>
            <a-menu slot='overlay'>
              <a-menu-item v-if="record.fankuanId!=''">
                  <a @click="$refs.refundDrewer.showDrawer({paymentId:record.fankuanId,parentId:record.paymentId},'form2')">查看返款单</a>
              </a-menu-item>
                <a-menu-item>
                  <a @click="$refs.drawer.showDrawer(record,'form2')">查看税金单</a>
              </a-menu-item>
                <a-menu-item v-if='record.fkPaymentState==1'>
                <a href='javascript:;' @click='processImg(record)'>返款进度</a>
              </a-menu-item>
              <a-menu-item v-if="record.fkPaymentState==0&&record.fankuanId!=''">
                <a href='javascript:;'
                   @click="$refs.table.del({paymentId:record.fankuanId},{handlerName:'refundPaymentDeleteHandler'})">删除返款</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
    </f-table>
    <invoice-drawer ref='drawer'></invoice-drawer>
    <refund-drawer ref='refundDrewer' @success='onLoad'></refund-drawer>
    <process-image ref='processImg' v-if='processImageVisible' :visible.sync='processImageVisible' :processInstanceId='processInstanceId'></process-image>
  </div>
</template>
<script>
import api from "./../js/api"
import RefundDrawer from "./refund_drawer"
import ProcessImage from "../../../flowable/process/process_image"
import InvoiceDrawer from "@/views/module/business/order/invoice/invoice_drawer"

export default {
  name: "SbreturnNo",
  components: { InvoiceDrawer, RefundDrawer, ProcessImage },
  data() {
    let me = this
    //操作按钮
    let operator = []

    return {
      api: Object.assign(api, this.api),
      //列表初始化查询参数
      queryParam: {},
      returnCustomBond: 0,
      processImageVisible: false,
      selectIds: "",
      params1: {
        supplierId: ""
      },
      // 表头
      columns: [
        {
          title: "#",
          width: "60px",
          align: "left",
          customRender: (text, record, index) => index + 1
        },
        {
          title: "操作",
          align: "left",
          width: "100px",
          scopedSlots: { customRender: "action" }
        },
        {
          title: "税金单号",
          align: "left",
          width: "100px",
          dataIndex: "paymentNo"
        },
        {
          title: "供货方",
          align: "left",
          width: "190px",
          ellipsis: true,
          dataIndex: "supplierName"
        },
        {
          title: "开票单位",
          align: "left",
          width: "190px",
          ellipsis: true,
          dataIndex: "invoiceunitName"
        },
        {
          title: "发票类型",
          align: "left",
          width: "80px",
          dataIndex: "invoiceType",
          scopedSlots: { customRender: "invoiceType" }
        },
        {
          title: "应返金额",
          align: "left",
          width: "100px",
          dataIndex: "supplierRetable"
        },
        {
          title: "开票金额",
          align: "left",
          width: "100px",
          dataIndex: "invoiceAmount"
        },
        {
          title: "开票税金",
          align: "left",
          width: "100px",
          dataIndex: "amount"
        },
        {
          title: "开票日期",
          align: "left",
          width: "100px",
          dataIndex: "amountDate"
        },
        {
          title: "支付人",
          align: "left",
          width: "80px",
          dataIndex: "payUserName"
        },
        {
          title: "支付日期",
          align: "left",
          width: "120px",
          dataIndex: "payDate"
        },
        {
          title: "创建日期",
          align: "left",
          width: "120px",
          sorter: true,
          dataIndex: "createTime"
        }
      ],
      operator: operator
    }
  },
  created() {
  },
  methods: {
    setData() {
    },
    //部门切换
    deptChange(value) {
      this.queryParam.deptId = value
      this.$refs.table.refresh(false)
    },
    /**
     * 查询事件
     * @param searchParams
     */
    searchTable(searchParams) {
      this.queryParam = Object.assign(this.queryParam, searchParams)
      this.$refs.table.refresh(true, searchParams)
    },
    //流程图
    processImg(record) {
      this.processInstanceId = record.fkProcessInstanceId
      this.processImageVisible = true
    },
    //重新提交
    completeTask(record) {
      this.http.confirm(this, {
        content: "确认提交审批吗?",
        url: api.tasktodo.complete,
        requestBody: true,
        data: {
          taskId: record.taskId
        },
        success: function(me, data) {
          me.$refs.table.refresh()
        }
      })
    },
    //提交审批
    startProcess(record) {
      this.http.confirm(this, {
        content: "确认提交审批吗?",
        url: api.processInstance.start,
        requestBody: true,
        data: {
          handlerName: "paymentRefundStartProcessHandler",
          businessKey: record.fankuanId
        },
        success: function(me, data) {
          me.$refs.table.refresh()
        }
      })
    },
    /**
     * 刷新列表
     */
    onLoad() {
      this.$refs.table.refresh()
      this.$emit("changeTab")
    }
  }
}
</script>
